#选择排序(
def selectSort(l:list):
    cout = 0
    for i,k in enumerate(l):
        minindex=i
        for x in range(i+1,len(l)):
            cout += 1
            if l[x]<l[minindex]:
                minindex=x
        if minindex !=i:
            l[i],l[minindex]=l[minindex],l[i]
    print(cout)
#e二元选择排序
def selectSort2(l:list):
    cout=0
    for i, k in enumerate(l):
        minindex = i
        maxindex=len(l)-i-1
        for x in range(i + 1, len(l)-i):
            cout+=1
            if l[x] < l[minindex]:
                minindex = x
            if l[x]>l[maxindex]:
                maxindex=x
        l[i],l[minindex]=l[minindex],l[i]
        l[len(l)-i-1],l[maxindex]=l[maxindex],l[len(l)-i-1]
    print(cout)

if __name__ == '__main__':
    l=[1,3,5,9,7,2,3,1,5,12,33,-233,-199394,12,3344,345454,1233,1233,12233,1233]
    selectSort(l)
    print(l)
    l2=[1,3,5,9,7,2,3,1,5,12,33,-233,-199394,12,3344,345454,1233,1233,12233,1233]
    print("------------")
    print(selectSort2(l2))
    print(l2)
    #测试删除变量
    a=12
    b=24
    dict1=dict(a=a,b=b)
    print(dict1)
    print(id(a))
    del a
    del b
    print("---------")
    print(dict1)
    print(id(dict1.get('a')))
    #闭包测试
    def counter():
        c=12
        def inc():
            nonlocal c
            c+=1
            return c
        return inc
    col=counter()
    print(col())
    print(col())
    print(col())
    c=100
    print(col())
    #树 二叉树结构
    #生成器版fib
    def fib():
        x=0
        y=1
        while True:
            x,y=y,x+y
            yield y
    foo=fib()
    for i in range(11):
        print(next(foo))
